package com.dimong.www.loan.db;

import android.content.Context;

import com.dimong.loan.sdk.db.DBHelper;
import com.j256.ormlite.dao.Dao;
import com.j256.ormlite.support.ConnectionSource;
import com.j256.ormlite.table.TableUtils;

import java.sql.SQLException;

public class LoanDBHelper extends DBHelper {

    private Dao<CheckModel, Integer> mCheckDao = null;

    public LoanDBHelper(Context mContext) {
        super(mContext, "loan", 1);
    }

    @Override
    public void createDBTable(ConnectionSource connectionSource) {
        try {
            TableUtils.createTable(connectionSource, CheckModel.class);
            TableUtils.createTable(connectionSource, CheckTotalModel.class);
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

    @Override
    public void upGradeDBTable(ConnectionSource connectionSource, int oldVersion, int newVersion) {
        try {
            TableUtils.dropTable(connectionSource, CheckModel.class, true);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        createDBTable(connectionSource);
    }

    public Dao<CheckModel, Integer> getRecordDao() {
        try {
            if (mCheckDao == null) {
                mCheckDao = getDao(CheckModel.class);
            }
            return mCheckDao;
        } catch (SQLException e) {
        }
        return null;
    }
}
